//
//  GAKKIConfig.h
//  GANGAIKit
//
//  Created by fh on 2019/11/6.
//  Copyright © 2019 cashchina. All rights reserved.
//

/**
一些基础公用宏
*/
#ifndef GAKKIConfig_h
#define GAKKIConfig_h

// 是否打印日志,默认DEBUG模式打印,可修改-> 1:打印 0:不打印
#if DEBUG
#define DBLOG_ENABLED 1
#else
#define DBLOG_ENABLED 0
#endif

// 输出日志 (格式: [时间] [哪个方法] [哪行] [输出内容])
#if DBLOG_ENABLED
#define DBLog(format, ...) printf("\n🔐:[%s] \n🐷🐶:%s [第%d行] \n%s\n", __TIME__, __FUNCTION__, __LINE__, [[NSString stringWithFormat:format, ##__VA_ARGS__] UTF8String]); // OS_ACTIVITY_MODE disable
#else
// 不打印,执行空语句
#define DBLog(...) ;
//#define DBLog(...) fprintf(stderr, "当前为日志打印关闭模式\n");
#endif

// 是否打印模型释放内存Log: 默认不打印,需要打印将0修改为1
#define kDebugModelRelease (0 && DBLOG_ENABLED)
// 是否打印视图释放内存Log: 默认不打印,需要打印将0修改为1
#define kDebugViewRelease (0 && DBLOG_ENABLED)
// 是否打印可重用视图释放内存Log: 默认不打印,需要打印将0修改为1
#define kDebugReusableViewRelease (0 && DBLOG_ENABLED)
// 是否打印控制器释放内存Log: 默认打印,不需要打印将1修改为0
#define kDebugViewControllerRelease (1 && DBLOG_ENABLED)

// 打印当前方法名
#define NSLogFunc NSLog(@"%s", __func__)


/**
 类型相关
 */
// 是否是iPhone设备
#define kIsiPhone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) // 🤪
// 是否是iPad设备
#define kIsiPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
// 是否是Retina
#define kIsRetina ([[UIScreen mainScreen] scale] >= 2.0)

/**
 屏幕尺寸相关
 */
// 屏幕宽
#define kkScreenWidth  ([[UIScreen mainScreen] bounds].size.width)
// 屏幕高
#define kkScreenHeight ([[UIScreen mainScreen] bounds].size.height)
// 屏幕尺寸
#define kkScreenBounds ([[UIScreen mainScreen] bounds])
// 屏幕尺寸宽高中的最大者
#define kkScreenMaxLength (MAX(kkScreenWidth, kkScreenHeight))
// 屏幕尺寸宽高中的最小者
#define kkScreenMinLength (MIN(kkScreenWidth, kkScreenHeight))

//#define kWidthScalePt(w,x) (w)

/**
 手机类型相关
 */
// 是否是iPhone4及以下设备
#define kIsiPhone4OrLess  (kIsiPhone && kkScreenMaxLength  < 568.0)
// 是否是iPhone5,5s或者SE设备
#define kIsiPhone5SoOn  (kIsiPhone && kkScreenMaxLength == 568.0)
// 是否是iPhone6,6s,7或者8设备
#define kIsiPhone6SoOn    (kIsiPhone && kkScreenMaxLength == 667.0)
// 是否是iPhone6P,6sP,7P或者8P设备
#define kIsiPhone6PSoOn    (kIsiPhone && kkScreenMaxLength == 736.0)
/// 是否是iPhoneX,iPhoneXS
#define kIsiPhoneX  (kIsiPhone && kkScreenMaxLength == 812.0)
/// 是否是iPhoneXSMax,iPhoneXR
#define kIsiPhoneXSMax (kIsiPhone && kkScreenMaxLength == 896.0)

// 屏幕比例像素点
#define kScaleW(x) (kkScreenWidth * (x) / 375.0)
#define kScaleH(y) (kkScreenHeight * (x) / 667.0)

/**
 iOS版本
 */
#define kiOSVersion [[[UIDevice currentDevice] systemVersion] floatValue]
#define kiOS7VerstionLater ([UIDevice currentDevice].systemVersion.floatValue >= 7.0)
#define kiOS8VerstionLater ([UIDevice currentDevice].systemVersion.floatValue >= 8.0)
#define kiOS9VerstionLater ([UIDevice currentDevice].systemVersion.floatValue >= 9.0)
#define kiOS10VerstionLater ([UIDevice currentDevice].systemVersion.floatValue >= 10.0)

// 导航条高度
#define kApplicationTopBarHeight ((kIsiPhoneXSMax==YES || kIsiPhoneX ==YES) ? 88.0f : 64.0f)
// tabBar高度
#define kApplicationTabBarHeight ((kIsiPhoneXSMax==YES || kIsiPhoneX ==YES) ? 83.0f : 49.0f)
// 状态栏高度
#define kApplicationStatusBarHeight ((kIsiPhoneXSMax==YES || kIsiPhoneX ==YES) ? 44.0f : 20.0f)

// 底部间距
#define kApplicationBottomSpace ((kIsiPhoneXSMax==YES || kIsiPhoneX ==YES) ? 34.0f : 0.0f) // 34:0.0f
// 顶部间距
#define kApplicationTopSpace ((kIsiPhoneXSMax==YES || kIsiPhoneX ==YES) ? 20.0f : 0.0f) // 34:0.0f

// UI颜色
#define UIColorFromHex(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 green:((float)((hex & 0xFF00) >> 8))/255.0 blue:((float)(hex & 0xFF))/255.0 alpha:1.0]
#define UIColorFromRGB(R,G,B) [UIColor colorWithRed:R/255.f green:G/255.f blue:B/255.f alpha:1.0]
#define UIColorFromRGBA(R,G,B,A) [UIColor colorWithRed:R/255.f green:G/255.f blue:B/255.f alpha:A/1.0]

/**
 适配iPhone X + iOS 11 : 可以在AppDelegate里面使用
     if (@available(iOS 11.0, *)){
         [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
     }
 全局统一设置或者使用宏kGlobalFitIOS11AutoSafeArea
 */
#define  kAdjustsScrollViewInsets_Never(__scrollView)\
do {\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
if ([__scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
NSInteger argument = 2;\
invocation.target = __scrollView;\
invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
[invocation setArgument:&argument atIndex:2];\
[invocation retainArguments];\
[invocation invoke];\
}\
_Pragma("clang diagnostic pop")\
} while (0)

/**
 全局统一去掉滚动控件自动适配安全区域，iPhoneX设备的导航栏和tabBar需要自己适配高度
 */
#define kGlobalAdjustsScrollViewInsetsForIOS11 \
if (@available(iOS 11.0, *)){\
    [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];\
}

/**
 判断是否是iOS11
 #ifdef __IPHONE_11_0
 
 #endif
 */

/** 字符串为空*/
#define kStringIsEmpty(str)     (str == nil || [str isKindOfClass:[NSNull class]] || [str length] < 1 || [str isEqualToString:@"(null)"] || [str isEqualToString:@"<null>"] || [str isEqualToString:@"<Null>"]? YES : NO )
/** 字符串不为空*/
#define kStringIsNotEmpty(str)  (!kStringIsEmpty(str))
/** 字符串为空的话返回@"" */
#define kEmptyString(str) (kStringIsEmpty(str)?@"":str)


#define BaseWeak(original,now) __weak typeof(original) now = original
#define BaseStrong(original,now) __strong typeof(original) now = original

#define WeakSelf BaseWeak(self,weakSelf)
#define StrongSelf BaseStrong(self,strongSelf)

#endif /* GAKKIConfig_h */
